﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using 纸片人.CalculateControls;
using 纸片人.InterfaceFolder;

//https://go.microsoft.com/fwlink/?LinkId=234236 上介绍了“用户控件”项模板

namespace 纸片人.win2dEffectControl.SliderFloder
{
    public sealed partial class Vector4Control : UserControl,IValueChange
    {
        public object Header
        {
            get { return (object)GetValue(HeaderProperty); }
            set { SetValue(HeaderProperty, value); }
        }

        // Using a DependencyProperty as the backing store for Header.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty HeaderProperty =
            DependencyProperty.Register("Header", typeof(object), typeof(Vector4Control), new PropertyMetadata(null));




        public Vector4 Vector4
        {
            get { return (Vector4)GetValue(Vector4Property); }
            set { SetValue(Vector4Property, value); }
        }

        // Using a DependencyProperty as the backing store for Vector4.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty Vector4Property =
            DependencyProperty.Register("Vector4", typeof(Vector4), typeof(Vector4Control), new PropertyMetadata(new Vector4(),Vector4Changed));

        private static void Vector4Changed(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var rpc = d as Vector4Control;
            if (rpc != null)
            {
                rpc.SetVector4((Vector4)e.NewValue);
            }
        }

       
        public event ValueChangedHeader ValueChanged;
        public event ValueChangedHeader ValueChangeing;

        public Vector4Control()
        {
            this.InitializeComponent();
        }

        private void Slider_Changing(TextBoxSlider sender, double newValue)
        {
            Vector4 = GetVector4();

            ValueChangeing?.Invoke(this, Vector4);
        }

        private void Slider_Changed(TextBoxSlider sender, double newValue, double oldValue)
        {
            Vector4 = GetVector4();
            ValueChanged?.Invoke(this, Vector4);

        }


        public void SetVector4(Rect rect)
        {
            //xSlider.Value = rect.X;
            //ySlider.Value = rect.Y;
            //widthSlider.Value = rect.Width;
            //heightSlider.Value = rect.Height;
        }

        public void SetVector4(Vector4 vector)
        {

            SetVector4(new Rect(vector.X, vector.Y, vector.Z, vector.W));
        }

        public void SetVector4(double x, double y, double width, double height)
        {
            SetVector4(new Rect(x, y, width, height));
        }

        public Vector4 GetVector4()
        {
            //var vector = new Vector4((float)xSlider.Value, (float)ySlider.Value, (float)widthSlider.Value, (float)heightSlider.Value); ;

            //return vector;
            return new Vector4();
        }

    }
}
